package com.dylovedz.javafxphone.service;

import cn.hutool.core.io.FileUtil;
import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 * @author Administrator
 */
@Service
@Slf4j
public class Pdf2wordService {
    public void pdf2word(String path, String outPath) {
        try {
            Document doc = new Document(FileUtil.getInputStream(path));
            doc.save(outPath, com.aspose.pdf.SaveFormat.DocX);
            doc.close();
            log.info("转换成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void word2pdf(String path, String outPath) {
        try {
            InputStream inputStream = FileUtil.getInputStream(path);
            com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);
            doc.save(outPath, com.aspose.words.SaveFormat.PDF);
            doc.cleanup();
            log.info("转换成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
